/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * viewDriver.java
 *
 * Created on Feb 24, 2011, 9:35:48 PM
 */

package Apogeesrc;
import javax.swing.*;
import java.sql.*;
import javax.swing.*;
/**
 *
 * @author Chrysler
 */
public class viewDriverPresident extends sqlConnection {
private ResultSet rs;
private Statement st;
private Connection conn;
int length = 100;

private String[][] viewDriverArr = new String[length][12];
private String[] driverArr = new String[length];
private String[] taxiArr = new String[length];
private String[] nameArr = new String[length];
private String[] bdayArr = new String[length];
private String[] genderArr = new String[length];
private String[] socialArr = new String[length];
private String[] cityArr = new String[length];
private String[] stArr = new String[length];
private String[] landlineArr = new String[length];
private String[] mobileArr = new String[length];
private String[] bgArr = new String[length];
private String[] joindateArr = new String[length];

    /** Creates new form viewDriver */
    public viewDriverPresident() {
        int ctr, ictr;
        initComponents();
        setVisible(true);

        jTable1.setEnabled(false);
        for(ictr = 0; ictr<length; ictr++){
               driverArr[ictr] = "";
               taxiArr[ictr] = "";
               nameArr[ictr] = "";
               bdayArr[ictr] = "";
               genderArr[ictr] = "";
               socialArr[ictr] = "";
               cityArr[ictr] = "";
               stArr[ictr] = "";
               landlineArr[ictr] = "";
               mobileArr[ictr] = "";
               bgArr[ictr] = "";
               joindateArr[ictr] = "";
        }


        conn = openConnection();
        rs = select(conn,"select driverID from driver");
        driverArr = copyToArr(conn, driverArr, rs, "driverID"); 

        rs = select(conn,"select taxiNum from driver");
        taxiArr = copyToArr(conn, taxiArr, rs, "taxiNum");

        rs = select(conn,"select name from driver");
        nameArr = copyToArr(conn, nameArr, rs, "name");

        rs = select(conn,"select bday from driver");
        bdayArr = copyToArr(conn, bdayArr, rs, "bday");

        rs = select(conn,"select gender from driver");
        genderArr = copyToArr(conn, genderArr, rs, "gender");

        rs = select(conn,"select socialStat from driver");
        socialArr = copyToArr(conn, socialArr, rs, "socialStat");

        rs = select(conn,"select city from driver");
        cityArr = copyToArr(conn, cityArr, rs, "city");

        rs = select(conn,"select street from driver");
        stArr = copyToArr(conn, stArr, rs, "street");

        rs = select(conn,"select landlineNum from driver");
        landlineArr = copyToArr(conn, landlineArr, rs, "landlineNum");

        rs = select(conn,"select mobileNum from driver");
        mobileArr = copyToArr(conn, mobileArr, rs, "mobileNum");

        rs = select(conn,"select bginfo from driver");
        bgArr = copyToArr(conn, bgArr, rs, "bginfo");

        rs = select(conn,"select joinDate from driver");
        joindateArr = copyToArr(conn, joindateArr, rs, "joinDate");

        for(ictr = 0;ictr< length;ictr++){
               viewDriverArr[ictr][0] = driverArr[ictr];
               viewDriverArr[ictr][1] = taxiArr[ictr];
               viewDriverArr[ictr][2] = nameArr[ictr];
               viewDriverArr[ictr][3] = bdayArr[ictr];
               viewDriverArr[ictr][4] = genderArr[ictr];
               viewDriverArr[ictr][5] = socialArr[ictr];
               viewDriverArr[ictr][6] = cityArr[ictr];
               viewDriverArr[ictr][7] = stArr[ictr];
               viewDriverArr[ictr][8] = landlineArr[ictr];
               viewDriverArr[ictr][9] = mobileArr[ictr];
               viewDriverArr[ictr][10] = bgArr[ictr];
               viewDriverArr[ictr][11] = joindateArr[ictr];
        }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(viewDriverArr, new String [] {"Driver id", "Taxi Body #", "Driver Name", "Birthday", "City", "Street", "Landline #", "Mobile #", "Absences", "Leaves", "Suspensions"}));


        closeConnection(conn);



        //JUST CHECKIN
        //try{
        //    new JOptionPane().showMessageDialog(null, driverArr[1]);
        //}catch(Exception e){new JOptionPane().showMessageDialog(null, e.getMessage()+" from vewiDriverPresdient");}




    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton6 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        jButton6.setText("jButton6");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"0005", new Integer(5), "Joshua Sy", "2011-01-01", "Manila", "Paco", new Long(88888), new Long(555555555), null, null, null},
                {null, null, null, null, "", null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Driver id", "Taxi Body #", "Driver Name", "Birthday", "City", "Street", "Landline #", "Mobile #", "Absences", "Leaves", "Suspensions"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Long.class, java.lang.Long.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Apogeesrc/converted images/back.jpg"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Apogeesrc/converted images/add.jpg"))); // NOI18N
        jButton4.setText("Add");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Apogeesrc/converted images/process.jpg"))); // NOI18N
        jButton7.setText("Update");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jLabel1.setText("President Driver View");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 356, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(366, 366, 366))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 814, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(50, 50, 50))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(25, 25, 25))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton7))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        setVisible(false);
        new viewMenuPresident();
}//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
setVisible(false);
new addDriver();// TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
if(jButton7.getText().equals("Update")){
            jButton7.setText("Done");
            new JOptionPane().showMessageDialog(null, "You can now edit the tables");
            jTable1.setEnabled(true);
        }else if(jButton7.getText().equals("Done")){
            new JOptionPane().showMessageDialog(null, "Table data locked");
            jButton7.setText("Update");
            jTable1.setEnabled(false);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new viewDriverPresident().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
